package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author guozh
 */
@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     *
     * @param id 分类id
     * @return 套餐数量
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 根据菜品id查询对应的套餐id
     *
     * @param dishIds dishIds
     * @return List<Long>
     */
    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);

    /**
     * 修改状态
     *
     * @param setmeal 状态
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 增加套餐
     *
     * @param setmeal 套餐数据
     */
    @AutoFill(value = OperationType.INSERT)
    void insertSetmeal(Setmeal setmeal);

    /**
     * 套餐分页查询
     *
     * @param setmealPageQueryDTO 套餐分页查询数据
     * @return Result<PageResult>
     */
    Page<SetmealVO> selectPageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查找
     *
     * @param ids id
     * @return Setmeal
     */
    Setmeal getById(List<Long> ids);

    /**
     * 根据id删除
     *
     * @param ids id
     */
    void deleteByIds(List<Long> ids);

    /**
     * 根据id查找
     *
     * @param id id
     * @return etmealVO
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal selectById(Long id);

    /**
     * 根据分类id查询套餐
     *
     * @param setmeal 分类id
     * @return Result<List < SetmealVO>>
     */

    List<SetmealVO> selectByCategoryId(Setmeal setmeal);

    /**
     * 根据套餐id查询包含的菜品
     *
     * @param id id
     * @return Result<SetmealVO>
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long id);
}
